/**
	Õ¯∏Òº”‘ÿ£¨Ωˆ÷ß≥÷.objŒƒº˛
*/

#ifndef _UFL_Mesh_H_
#define _UFL_Mesh_H_

#include "UFLBaseType.h"
#include "fbxsdk.h"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using std::vector;
using std::fstream;
using std::string;


namespace ufl
{
	//---------------------//
	//--  UFL Base Mesh  --//
	//---------------------//
	class UFLMesh
	{
	public:
		UFLMesh();
		virtual ~UFLMesh();

	public:
		virtual void beginDraw();
		virtual void draw() = 0;
		virtual void endDraw();

	protected:
		enum 
		{
			VERTEX_VBO,
			INDEX_VBO,
			VBO_COUNT
		};

		ufl_uint32 _vao_id;
		ufl_uint32 _vbo_ids[VBO_COUNT];
		bool _hasNormal, _hasUV;
	};

	//---------------------//
	//--  UFL FBX Mesh   --//
	//---------------------//
	class UFLFbxMesh : public UFLMesh
	{
	public:
		UFLFbxMesh();
		virtual ~UFLFbxMesh();

		bool import(const char* filename);
		virtual void draw();

	private:
		void parseNode(FbxNode* node);
		void parseMesh(FbxNode* node);

	private:
		struct SubMesh
		{
			SubMesh() : IndexOffset(0), TriangleCount(0) {}

			int IndexOffset;
			int TriangleCount;
		};
		FbxArray<SubMesh*> _subMeshes;
	};

	//---------------------//
	//-- UFL Sphere Mesh --//
	//---------------------//
	class UFLSphereMesh : public UFLMesh
	{
	public:
		UFLSphereMesh();
		virtual ~UFLSphereMesh();

		void init(ufl_float radius, ufl_uint32 slices, ufl_uint32 stacks);
		virtual void draw();

	private:
		ufl_uint32 _numIndices;
	};

	//----------------------//
	//--  UFL Plane Mesh  --//
	//----------------------//
	class UFLPlaneMesh : public UFLMesh
	{
	public:
		UFLPlaneMesh();
		~UFLPlaneMesh();

		void init(ufl_float xsize, ufl_float zsize, ufl_int32 xdivs, ufl_int32 zdivs, ufl_float smax = 1.0f, ufl_float tmax = 1.0f);
		virtual void draw();

	private:
		ufl_uint32 _numIndices;
	};
    
    //-----------------------//
	//--   UFL Cube Mesh   --//
	//-----------------------//
    class UFLCubeMesh : public UFLMesh
    {
    public:
        UFLCubeMesh();
        virtual ~UFLCubeMesh();
        
        void init(ufl_float side = 1.0f);
        virtual void draw();
    };
}
#endif